//
//  ModuelCell.m
//  Project
//
//  Created by 冯东辉 on 2018/9/20.
//  Copyright © 2018年 FengDongHui. All rights reserved.
//

#import "ModuelCell.h"

@implementation ModuelCell

- (void)awakeFromNib {
    
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    [super setSelected:selected animated:animated];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self creatSubViews];
    }
    
    return self;
}

- (void)creatSubViews {
    
    CGFloat height = (GET_SCREEN_HEIGHT()-SafeAreaTopHeight)/5.0f - 10;
    
    _baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, GET_SCREEN_WIDTH()-20, height)];
//    CAGradientLayer *layer = [CAGradientLayer layer];
//    layer.frame = _baseView.bounds;
//    [_baseView.layer addSublayer:layer];
    [self.contentView addSubview:_baseView];
    
    CGFloat maxHeight = height/2.0f;
    
    CGFloat font = 15;
    
    CGFloat c_width = 36;
    
    CGFloat x_width = 16;
    
    CGFloat l_width = 50;
    
    if (GET_SCREEN_HEIGHT() == 667) {
        font = 18;
        
        c_width = 40;
        x_width = 20;
        l_width = 55;
        
    }else if (GET_SCREEN_HEIGHT() == 736) {
        font = 20;
        c_width = 43;
        x_width = 23;
        l_width = 58;
        
    }else if (GET_SCREEN_HEIGHT() >= 812) {
        font = 22;
        c_width = 46;
        x_width = 26;
        l_width = 61;
    }
    
    _title_l = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, _baseView.width-10-c_width-l_width, maxHeight)];
    _title_l.textColor = UICOLOR_HEX(0xffffffff);
    _title_l.textAlignment = NSTextAlignmentLeft;
    _title_l.font = [UIFont systemFontOfSize:font];
    _title_l.numberOfLines = 0;
    [_baseView addSubview:_title_l];
    
    _content_l = [[UILabel alloc] initWithFrame:CGRectMake(20, _title_l.bottom, _baseView.width-20, maxHeight)];
    _content_l.textColor = UICOLOR_HEX(0xffffffff);
    _content_l.textAlignment = NSTextAlignmentLeft;
    _content_l.font = [UIFont boldSystemFontOfSize:font+10];
    [_baseView addSubview:_content_l];
    
    _collect_btn = [[UIButton alloc] initWithFrame:CGRectMake(_baseView.width-c_width, _title_l.top, c_width, _title_l.height)];
    [_baseView addSubview:_collect_btn];
    
    _collect_img = [[UIImageView alloc] initWithFrame:CGRectMake((_collect_btn.width-x_width)/2.0f, (_collect_btn.height-x_width)/2.0f, x_width, x_width)];
    [_collect_btn addSubview:_collect_img];
    
    _lieH_view = [[UIImageView alloc] initWithFrame:CGRectMake(_baseView.width-_collect_btn.width-l_width, _title_l.top+(_title_l.height-x_width)/2.0f, l_width, x_width)];
    _lieH_view.image = [UIImage imageNamed:@"module_lhzb"];
    [_baseView addSubview:_lieH_view];
    
    _status_view = [[UIImageView alloc] initWithFrame:CGRectMake(_collect_btn.left+(_collect_btn.width-18)/2.0f, _content_l.top, 18, _content_l.height)];
    _status_view.contentMode = UIViewContentModeCenter;
    [_baseView addSubview:_status_view];
    
    _status_l = [[UILabel alloc] initWithFrame:CGRectMake(0, _content_l.top, _status_view.left, _content_l.height)];
    _status_l.textAlignment = NSTextAlignmentRight;
    _status_l.font = [UIFont boldSystemFontOfSize:font];
    [_baseView addSubview:_status_l];
    
}

- (void)reloadSubViewWithData:(NSMutableArray *)data indexPath:(NSIndexPath *)indexPath {
    
    NSDictionary *dic = [data objectAtIndex:indexPath.row];
    
    CGFloat c_width = 36;
    CGFloat l_width = 50;
    
    if (GET_SCREEN_HEIGHT() == 667) {
        c_width = 40;
        l_width = 55;
    }else if (GET_SCREEN_HEIGHT() == 736) {
        c_width = 43;
        l_width = 58;
    }else if (GET_SCREEN_HEIGHT() >= 812) {
        c_width = 46;
        l_width = 61;
    }
    
    // 劣化指标 1劣化 0没劣化
    NSInteger iS_Degradation = [dic[@"iS_Degradation"] integerValue];
    if (iS_Degradation == 0) {
        _lieH_view.hidden = YES;
        _title_l.width = _baseView.width-10-c_width;
    }else {
        _lieH_view.hidden = NO;
        _title_l.width = _baseView.width-10-c_width-l_width;
    }
    
    _title_l.text = [NSString stringWithFormat:@"%@", dic[@"inD_Name"]];
    
    NSString *inD_DATA = [NSString stringWithFormat:@"%@", dic[@"inD_DATA"]];
    if ([ProjectTools isValiString:inD_DATA]) {
        inD_DATA = @"0.00";
    }
    _content_l.text = [NSString stringWithFormat:@"%.2f", [inD_DATA floatValue]];
    
    // 是否收藏 0未收藏 1 收藏
    NSInteger inD_FAV = [dic[@"inD_FAV"] integerValue];
    if (inD_FAV == 0) {
        _collect_img.image = [UIImage imageNamed:@"module_collect"];
    }else {
        _collect_img.image = [UIImage imageNamed:@"module_collect_sel"];
    }
    
    _collect_btn.tag = indexPath.row+999;
    
    // 状态 1上升 2下降 0持平
    NSInteger rise = [dic[@"rise"] integerValue];
    
    NSString *lasttime_data = [NSString stringWithFormat:@"%@", dic[@"lasttime_data"]];
    if ([ProjectTools isValiString:lasttime_data]) {
        lasttime_data = @"0.00";
    }
    NSString *status_text = [NSString stringWithFormat:@"%.2f", [lasttime_data floatValue]];
    
    if ([ProjectTools isValiString:status_text]) {
        status_text = @"0.00";
    }
    
    _status_l.text = status_text;
    
    if (rise == 0) {
        
        _status_view.image = [UIImage imageNamed:@"module_pingji"];
        _status_l.textColor = UICOLOR_HEX(0xffffffff);
        
    }else if (rise == 1) {
        
        _status_view.image = [UIImage imageNamed:@"module_shangsheng"];
        _status_l.textColor = UICOLOR_HEX(0xff29fd31);
        
    }else {
        
        _status_view.image = [UIImage imageNamed:@"module_xiajiang"];
        _status_l.textColor = UICOLOR_HEX(0xfff95154);
    }
}

@end
